
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.DomElement;
import com.gargoylesoftware.htmlunit.html.DomNodeList;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

public class Mypc {
	public void testUserHttpUnit() throws Exception{
		WebClient wc = new WebClient(BrowserVersion.CHROME);
	    wc.getOptions().setUseInsecureSSL(true);  
	    wc.getOptions().setJavaScriptEnabled(true); // 启用JS解释器，默认为true  
	    wc.getOptions().setCssEnabled(false); // 禁用css支持  
	    wc.getOptions().setThrowExceptionOnScriptError(false); // js运行错误时，是否抛出异常  
	    wc.getOptions().setTimeout(0); // 设置连接超时时间 ，这里是10S。如果为0，则无限期等待  
	    wc.getOptions().setDoNotTrackEnabled(false); 
	    HtmlPage page = wc  
	            .getPage("https://blog.csdn.net/u010833696/article/details/45740871");  
	  
	    DomNodeList<DomElement> links = page.getElementsByTagName("a");  
	  System.out.println("爬取中...");
	    for (DomElement link : links) {  
	        System.out.println(link.asText() + "  " + link.getAttribute("href"));  
	    } 
	}
	public static void main(String[] args) throws Exception {
		Mypc a=new Mypc();
		a.testUserHttpUnit();
	}

}
